home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / ERRCRIT / L1C.C next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.5 KB  |  48 lines

  1. // Dynamic link library implementation of NeuroSolutions L1Criterion component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /***********************************/
  6. /* Forward activation of component */
  7.  
  8. __declspec(dllexport) NSFloat performCriterion(
  9.     DLLData    *instance,        // Pointer to instance data (may be NULL)
  10.     NSFloat *costDerivative,     // Pointer to the cost derivative vector, i.e. output sensitivity
  11.     int     rows,            // Number of rows of PEs in the layer
  12.     int     cols,            // Number of columns of PEs in the layer
  13.     NSFloat *output,         // Pointer to the output layer of the network
  14.     NSFloat *desired,        // Pointer to the desired output vector, same length as output layer
  15.     BOOL    testing            // Flag to indicate whether or not the data is for the test set
  16.     )
  17. {
  18.     int i,length=rows*cols;
  19.     NSFloat cost=0.0f;
  20.     NSFloat error;
  21.  
  22.     for (i=0; i<length; i++) {
  23.         error = desired[i] - output[i];
  24.         costDerivative[i] = error < 0.0f ? -1.0f : error > 0.0f ? 1.0f : 0.0f;
  25.         cost += (NSFloat)fabs(error);
  26.     }
  27.     return cost;
  28. }
  29.  
  30. /******************************************/
  31. /* Management of instance data (OPTIONAL) */
  32. /*
  33. __declspec(dllexport) DLLData *allocCriterion(
  34.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  35.     int     rows,        // Number of rows of PEs in the layer
  36.     int     cols        // Number of columns of PEs in the layer
  37.     )
  38. {
  39.     DLLData *instance = allocDLLInstance(oldInstance);
  40.     return instance;
  41. }
  42.  
  43. __declspec(dllexport) void freeCriterion(DLLData *instance)
  44. {
  45.     freeDLLInstance(instance);
  46. }
  47. */
  48.